#include <iostream>
using namespace std;

const int N = 1e3+10;
int dp[N][N];
//dp[i][j] : 表示i -> j的最长回文子序列
//if(s[i] == s[j]) => dp[i][j] = dp[i+1][j-1]+2
//if(s[i] != s[j]) => dp[i][j] = max(dp[i][j-1],dp[i+1][j]);

int main() {
    string s;
    cin >> s;
    int n = s.size();
    for(int i = 0;i<=n;i++)
    {
        dp[i][i] = 1;
    }
    for(int i = n-1;i >= 0;i--)
    {
        for(int j = i + 1;j <= n-1;j++)
        {
            if(s[i] == s[j])
            {
                dp[i][j] = dp[i+1][j-1]+2;
            }
            else
            {
                dp[i][j] = max(dp[i][j],dp[i+1][j-1]);
                dp[i][j] = max(dp[i][j],dp[i+1][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
        }
    }
    cout << dp[0][n-1] << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")